package com.liu.juc.lock;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author LIU
 * @version 1.0
 * @description TODO
 * @date 2024/2/20 14:31
 * ConcurrentModificationException 异常演示
 *
 *
 */
public class CollectTest {
    public static void main(String[] args) {
//        List<String> list = new ArrayList<>();

        // 解决方法  synchronized关键字实现
//        List<String> list = new Vector<>();
//        List<String> list = Collections.synchronizedList(new ArrayList<>());

        // lock锁实现
        List<String> list = new CopyOnWriteArrayList<>();


        for (int i = 0; i < 30; i++) {
            new Thread(() -> {
                list.add(UUID.randomUUID().toString());
                System.out.println(list);
            }).start();
        }


        Map<Object, Object> map = new ConcurrentHashMap<>();
        map.put("1","11");
    }
}
